
$(function() {
	searchEntity();
});

//查询检索列表和左侧我的项目状态
function searchEntity() {
	var searchText = $("#searchText").val();
	var searchStatus = $("#searchStatus").val();
	$.ajax({
	  url: 'project!searchListByOrgUser.action',
	  type: 'post',
	  data: {
	  	"searchText": searchText,
	  	"searchStatus": searchStatus
	  },
	  dataType: 'json',
	  success: function(data) {
		  Interceptor(data);
	  	 // 左侧
	  	 var r = ''; 
	  	 $(data[0].statusList).each(function(i) {
	  	 	r += '<li><a href="javascript:void(0)" onclick="statusHandle(\'' + data[0].statusList[i].split(',')[1] + '\')" >' + data[0].statusList[i].split(',')[0] + '</a></li>';
	  	 });
	  	 $("#navData").html(r);
	     // 列表
	     var resultContent = '<tr>'
					          + '<th scope="col" width="120">注册号</th>'
					          + '<th scope="col">项目名称</th>'
					          + '<th scope="col">是否为干细胞<br>项目</th>'
					          + '<th scope="col">项目状态</th>'
					          + '<th scope="col" width="70">注册日期</th>'
					          + '<th scope="col" width="85">注册用户</th>'
					          + '<th scope="col" width="80">操作</th>'
					          + '</tr>';
	     $(data[0].list).each(function(i) {
	     		var statusStr = '';
	     		var operaStr = '';
	     		var trStr = '';
	     		var isSummarizeStr= '';
	     		var isStemCellProjectsStr = '';
	     		if(null!=data[0].list[i].isStemCellProjects && data[0].list[i].isStemCellProjects=='1') {
	     			isStemCellProjectsStr = '是';
	     		}else {
	     			isStemCellProjectsStr = '否';
	     		}
	     		if(i%2==0) {
	     			trStr = 'class="odd"';
	     		}
	     		if(data[0].list[i].isSummarize=='1') {
	     			isSummarizeStr = '<a href="project_summarize_detail.jsp?id=' + data[0].list[i].id + '">完成总结</a><br>';
	     		}else if(data[0].list[i].isSummarize=='0') {
	     			isSummarizeStr = '<a href="javascript:void(0)" onclick="alert(\'该项目无项目完成总结！\');">完成总结</a><br>';
	     		}
	     		
	     		// 判断状态
	     		if(data[0].list[i].status=='3') {
	     		    if(data[0].list[i].isProvinceManagerAudit=='0') {
	     		    	statusStr = '省级管理员驳回';
	     		    	if(data[0].list[i].roleType==2) {
		     				operaStr = '<a href="javascript:void(0)" onclick="alert(\'' + data[0].list[i].reason + '\')">审核意见</a><br>' 
		     					+ '<a href="javascript:void(0)" onclick="if(confirm(\'您确定要进行此操作吗?\')) passAuditProject(' 
				     			+ data[0].list[i].id + ');">通过</a><br><a href="project_reason.jsp?&status=2&id='
				     			+ data[0].list[i].id +'">不通过</a><br><a href="project_reason.jsp?&status=3&id='
				     			+ data[0].list[i].id +'">驳回</a><br>';
		     			}else {
		     				operaStr = '<a href="javascript:void(0)" onclick="alert(\'' + data[0].list[i].reason + '\')">审核意见</a><br>';
		     			}
	     		    }else {
	     		    	statusStr = '机构管理员驳回';
	     				operaStr = '<a href="javascript:void(0)" onclick="alert(\'' + data[0].list[i].reason + '\')">审核意见</a><br>';
	     		    }
	     		}else if(data[0].list[i].status=='0') {
	     			statusStr = '待机构管理员审查';
	     			if(data[0].list[i].roleType==2) {
	     				operaStr = '<a href="javascript:void(0)" onclick="if(confirm(\'您确定要进行此操作吗?\')) passAuditProject(' 
			     			+ data[0].list[i].id + ');">通过</a><br><a href="project_reason.jsp?&status=2&id='
			     			+ data[0].list[i].id +'">不通过</a><br><a href="project_reason.jsp?&status=3&id='
			     			+ data[0].list[i].id +'">驳回</a><br>';
	     			}else {
	     				operaStr = '无';
	     			}
	     			
	     		}else if(data[0].list[i].status=='1' && data[0].list[i].isProvinceManagerAudit=='0' ) {
	     			statusStr = '待省级管理员审查';
	     			if(data[0].list[i].roleType==1) {
	     				operaStr = '<a href="javascript:void(0)" onclick="if(confirm(\'您确定要进行此操作吗?\')) passAuditProject(' 
			     			+ data[0].list[i].id + ');">通过</a><br><a href="project_reason.jsp?&status=2&id='
			     			+ data[0].list[i].id +'">不通过</a><br><a href="project_reason.jsp?&status=3&id='
			     			+ data[0].list[i].id +'">驳回</a><br>';
	     			}else {
	     				operaStr = '无';
	     			}
	     		}else if( (data[0].list[i].status=='1' && data[0].list[i].isProvinceManagerAudit=='') || (data[0].list[i].status=='1' && data[0].list[i].isProvinceManagerAudit=='1') ) {
	     			statusStr = '审查通过';
	     			operaStr = '<a href="project_report.jsp?id=' + data[0].list[i].id + '">年度报告</a><br><a href="project_version.jsp?id=' 
	     					+ data[0].list[i].id + '">项目变更</a><br>' + isSummarizeStr;
	     		}else if(data[0].list[i].status=='2') {
	     			statusStr = '审查不通过';
	     			operaStr = '<a href="javascript:void(0)" onclick="alert(\'' + data[0].list[i].reason + '\')">审核意见</a><br>';
	     		}
				resultContent += '<tr ' + trStr +  '>'
                            	+ '<td height="30">' + data[0].list[i].regNumber + '</td>'
                                + '<td><h2><a href="/index/project_detail.jsp?id=' + data[0].list[i].id + '">' + data[0].list[i].name + '</a></h2></td>'
                                + '<td align="center">' + isStemCellProjectsStr + '</td>'
                                + '<td align="center" style="color: red;">' + statusStr + '</td>'
                                + '<td align="center">' + data[0].list[i].createTime.substring(0,10) + '</td>'
                                + '<td align="center">' + data[0].list[i].createUser.name + '</td>'
                                + '<td align="center">' + operaStr + '</td>'
                                + '</tr>';
		 });
		 
		 if(data[0].list==null || data[0].list=='') {
		 	resultContent += '<tr><td colspan="6" height="30">您还未登记任何项目信息！</td></tr>'
		 }
		 $("#mainData").html(resultContent); 
	  }, 
	  error: function() {
		  //
	  }
    });
}

function statusHandle(value){
	$("#searchStatus").val(value);
	searchEntity();
}

function passAuditProject(id) {
	$.ajax({
		url : 'project!auditProject.action',
		dataType: 'html',
		data:{
			"id": id,
			"reason": "",
			"status": "1"
		},
		success : function(data) {
			Interceptor(data);
		     if(data!=null && data=="success") {
		    	alert("操作成功！");
		    	searchEntity();
		     }
		},
		error : function() {
			alert("通信失败！");
		}
	 });
}

